home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre2.z / postgre2 / ref / information / postquel < prev   
Encoding:
Text File  |  1992-08-27  |  14.7 KB  |  632 lines

  1. .\" XXX standard disclaimer belongs here....
  2. .\" $Header: /private/postgres/ref/information/RCS/postquel,v 1.14 1992/07/14 05:54:17 ptong Exp $
  3. .SS COMMANDS 6/14/90
  4. .XA 0 "Section 4 \*- \*(PQ Commands (COMMANDS)"
  5. .SP POSTQUEL COMMANDS 6/14/90
  6. .sp 2i
  7. .ps 14
  8. .ce
  9. .b "SECTION 4 \*- \*(PQ COMMANDS (COMMANDS)"
  10. .sp 3
  11. .XA 1 "General Information"
  12. .uh DESCRIPTION
  13. .lp
  14. The following is a description of the general syntax
  15. of \*(PQ.
  16. Individual 
  17. \*(PQ
  18. statements and commands
  19. are treated separately in the document;
  20. this section describes the syntactic classes from which the constituent
  21. parts of 
  22. \*(PQ
  23. statements are drawn.
  24. .uh Comments
  25. .lp
  26. A
  27. .i comment
  28. is an arbitrary sequence of characters
  29. bounded on the left by
  30. ``/*''
  31. and on the right by
  32. ``*/'', e.g:
  33. .(l
  34. .ft C
  35. /* This is a comment */
  36. .ft
  37. .)l
  38. .uh "Names"
  39. .lp
  40. .i Names
  41. in \*(PQ
  42. are sequences of not more than 16 alphanumeric
  43. characters, starting with an alphabetic.
  44. Underscore (\^_\^) is considered
  45. an alphabetic.
  46. .uh "Keywords"
  47. .lp
  48. The following identifiers are reserved for use as
  49. .i keywords
  50. and may not be used otherwise:
  51. .lp
  52. .s3
  53. .ft B
  54. .if n .ta 5 18 31 44
  55. .if t .ta 0.5i 1.8i 3.1i 4.4i
  56. .de xx
  57. \t\\$1\t\\$2\t\\$3\t\\$4
  58. .br
  59. ..
  60. .xx abort delete key remove 
  61. .xx addattr demand leftouter rename 
  62. .xx after descending light replace
  63. .xx all destroy load retrieve
  64. .xx always destroydb merge returns
  65. .xx and do move rewrite
  66. .xx append empty never rightouter 
  67. .xx arch_store end new rule
  68. .xx archive execute none sort
  69. .xx arg fetch nonulls stdin
  70. .xx ascending forward not stdout
  71. .xx attachas from NULL store
  72. .xx backward function on to
  73. .xx before heavy once transaction
  74. .xx begin in operator type
  75. .xx binary index or union
  76. .xx by indexable output_proc unique
  77. .xx cfunction inherits parallel using
  78. .xx close input_proc pfunction vacuum
  79. .xx cluster instance portal variable
  80. .xx copy instead postquel version
  81. .xx create intersect priority view
  82. .xx createdb into purge where
  83. .xx current intotemp quel with
  84. .xx define is relation
  85. .ft
  86. .lp
  87. In addition,
  88. all \*(PP
  89. classes have several predefined attributes used
  90. by the system.
  91. For a list of these,
  92. see the section
  93. .b Fields ,
  94. below.
  95. .lp
  96. .uh "Constants"
  97. .lp
  98. There are six types of
  99. .i constants
  100. for use in \*(PQ.
  101. They are described below.
  102. .uh "Character Constants"
  103. .lp
  104. Single
  105. .i "character constants"
  106. may be used in \*(PQ by 
  107. surrounding them by single
  108. quotes, e.g., `n'.
  109. .uh "String Constants"
  110. .lp
  111. \fIStrings\fP in \*(PQ are arbitrary sequences of ASCII characters bounded by
  112. double quotes (" "). Upper case alphabetics within strings are
  113. accepted literally.
  114. Non-printing characters may be embedded within strings by prepending them
  115. with a backslash, e.g., `\en'. Also, in order to embed quotes
  116. within strings, it is necessary to prefix them with `\e' .
  117. The same convention applies to `\e' itself.
  118. Because of the limitations on instance sizes, string constants
  119. are currently limited to a length of a little less than 8K bytes.
  120. Larger objects may be created using the \*(PP Large Object interface.
  121. .uh "Integer Constants"
  122. .lp
  123. .i "Integer constants"
  124. in \*(PQ are collection of ASCII digits with no decimal point.
  125. Legal
  126. values 
  127. range from \(mi2147483647
  128. to +2147483647.
  129. This will vary depending on the operating system and host machine.
  130. .uh "Floating Point Constants"
  131. .lp
  132. .i "Floating point constants"
  133. consist of an integer part, a decimal point, and
  134. a fraction part or scientific notation
  135. of the following format:
  136. .(l
  137. .ft C
  138. {<dig>} .{<dig>} [e [+-] {<dig>}]
  139. .ft
  140. .)l
  141. .lp
  142. Where <dig> is a digit.
  143. You must include at least one <dig> after the period and after the
  144. [+-] if you use those options.
  145. An exponent with a missing mantissa has a mantissa
  146. of 1 inserted.
  147. There may be no extra characters embedded in the string.
  148. Floating constants
  149. are taken to be double-precision quantities with a range of
  150. approximately
  151. .if n -10**38 to +10**38
  152. .if t \(mi10\x'-0.2v'\u\s-3\&38\s0\d to 10\u\x'-0.2v'\s-3\&38\s0\d
  153. and a precision of 17 decimal digits.
  154. This will vary depending on the operating system and host machine.
  155. .uh "Constants of \*(PP User Defined Types"
  156. .lp
  157. A constant of an
  158. .i arbitrary
  159. type can be entered using the notation:
  160. .(l
  161. .ft C
  162. "string"::type-name
  163. .ft
  164. .)l
  165. In this case the value inside the string is passed to the input conversion
  166. routine for the type called type-name. The result is a constant of the
  167. indicated type.
  168. .lp
  169. .uh "Array constants"
  170. .lp
  171. .i "Array constants"
  172. are arrays of any \*(PP type, including other arrays, string constants,
  173. etc.  The general format of an array constant is the following:
  174. .(l
  175. .ft C
  176. "{<val1><delim><val2><delim>}"
  177. .ft
  178. .)l
  179. .lp
  180. An example of an array constant is
  181. .lp
  182. .(l
  183. .ft C
  184. "{{1,2,3},{4,5},{6,7,8,9}}"
  185. .ft
  186. .)l
  187. .lp
  188. This constant is an array consisting of three sub-arrays of integers.
  189. .lp
  190. .uh "Fields"
  191. .lp
  192. .i field
  193. is one of the following:
  194. .(l
  195. \fIattribute name in a given class\fR
  196. .ft C
  197. all
  198. oid
  199. tmin
  200. tmax
  201. xmin
  202. xmax
  203. cmin
  204. cmax
  205. vtype
  206. .ft
  207. .)l
  208. As in \*(II, 
  209. .i all
  210. is a shorthand for all normal attributes in a class, and may be used
  211. profitably in the target list of a retrieve statement.  
  212. .i Oid
  213. stands for the unique identifier of an instance which is added by \*(PP to
  214. all instances automatically. Oids are not reused and are 32 bit quantities.
  215. .lp
  216. .i "Tmin, tmax, xmin, cmin, xmax"
  217. and
  218. .i cmax
  219. stand respectively for the time that the instance was inserted, the time
  220. the instance was deleted, the identity of the inserting transaction, 
  221. the command identifier within the transaction,
  222. the identity of the deleting transaction and
  223. its associated deleting command.  For further information
  224. on these fields consult [STON87].  Times are represented internally
  225. as instances of the 
  226. .q "abstime"
  227. data type.  Transaction identifiers are
  228. 32 bit quantities which are assigned sequentially
  229. starting at 512.  Command identifiers are 16 bit objects;
  230. hence, it is an error
  231. to have more than 65535 \*(PQ commands within one transaction.
  232. .uh "Attributes"
  233. .lp
  234. An
  235. .i attribute
  236. is a construct of the form:
  237. .(l
  238. .ft C
  239. Instance-variable{.composite_field}.field `['number`]'
  240. .ft
  241. .)l
  242. .i Instance-variable 
  243. identifies a particular class and can be thought of
  244. as standing for the instances of that class.
  245. An instance variable is either a class name, a
  246. surrogate for a class defined by means of a
  247. .i from
  248. clause, or the keyword 
  249. .b new
  250. or 
  251. .b current.
  252. New and current can only appear in the action portion of a rule, while other instance
  253. variables can be used in any \*(PQ command. 
  254. .i Composite_field
  255. is a field of of one of the \*(PP composite types indicated in the 
  256. \fBinformation\fR(commands) section,
  257. while successive
  258. composite fields address attributes
  259. in the class(s) to which the composite field evaluates.
  260. Lastly, 
  261. .i field
  262. is a normal (base type) field in the class(s) last addressed.
  263. If
  264. .i field 
  265. is of type array, then the optional
  266. .i number 
  267. designator indicates a specific element in the array.  If no
  268. number is indicated, then all array elements are returned.
  269. .uh "Operators"
  270. .lp
  271. Any built-in system, or user defined operator
  272. may be used in \*(PQ.  For the
  273. list of built-in and system operators consult
  274. .b built-in
  275. types 
  276. (commands) and
  277. b. system types
  278. (commands).
  279. For a list of user defined
  280. operators consult your system administrator or run a query on the
  281. pg_operator class.
  282. Parentheses may be used for arbitrary grouping of operators.
  283. .uh "Expressions (a_expr)"
  284. .lp
  285. An
  286. .i expression
  287. is one of the following:
  288. .(l
  289. .ft C
  290. ( a_expr )
  291. constant
  292. attribute
  293. a_expr  binary_operator  a_expr
  294. .\" a_expr right_unary_operator
  295. left_unary_operator  a_expr
  296. parameter
  297. functional expressions 
  298. aggregate expressions
  299. set expressions
  300. class expression \fP(not in Version \*(PV)\fR
  301. .ft
  302. .)l
  303. We have already discussed constants and attributes.
  304. The two kinds
  305. of operator expressions indicate respectively binary and
  306. left_unary expressions.
  307. The following sections discuss the remaining
  308. options.
  309. .uh "Parameters"
  310. .lp
  311. .i parameter
  312. is used to indicate a parameter in a \*(PQ function.  Typically this
  313. is used in \*(PQ function definition statement.
  314. The form of a parameter is:
  315. .(l
  316. .ft C
  317. \'$' number
  318. .ft
  319. .)l
  320. .lp
  321. For example, consider the definition of a function, DEPT, as
  322. .(l
  323. .ft C
  324. define function DEPT 
  325.     (language="postquel", returntype = dept)
  326.     arg is (char16) as 
  327.     retrieve (dept.all) where dept.name = $1
  328. .ft
  329. .)l
  330. .uh "Functional Expressions"
  331. .lp
  332. A
  333. .i functional
  334. .i expression
  335. is the name of a legal \*(PQ function,
  336. followed by its argument list enclosed in parentheses, e.g.:
  337. .(l 
  338. .ft C
  339. fn-name (a_expr{ , a_expr})
  340. .ft
  341. .)l    
  342. For example, the following computes the square root of an employee salary.
  343. .(l
  344. .ft C
  345. sqrt(emp.salary)
  346. .ft
  347. .)l
  348. .uh "Aggregate Expression"
  349. .lp
  350. An
  351. .i aggregate
  352. .i expression
  353. represents a simple aggregate (i.e one which
  354. computes a single value) or an aggregate function (i.e. one which 
  355. computes a set
  356. of values).
  357. The syntax is the following:
  358. .(l
  359. .ft C
  360. aggregate_name `{' [unique [using] opr] a_expr
  361.         [from from_list]
  362.         [where qualification]`}'
  363. .ft
  364. .)l
  365. Here, 
  366. .i aggregate_name 
  367. must be a previously defined aggregate.  The 
  368. .i from_list 
  369. indicates the class to be aggregated over while
  370. .i qualification
  371. gives restrictions which must be satisfied by the instances to be aggregated.
  372. Next, the a_expr gives the expression to be aggregated while
  373. the 
  374. .i unique
  375. tag indicates whether all values should be aggregated or just the
  376. unique values of a_expr.
  377. Two expressions, a_expr1 and a_expr2 are the same if
  378. a_expr1 opr a_expr2 evaluates to true.
  379. .lp
  380. In the case that all instance variables used in the aggregate expression
  381. are defined in the from list, a simple aggregate has been defined.  For
  382. example, to sum employee salaries whose age is greater than 30, one would
  383. write:
  384. .(l
  385. .ft C
  386. retrieve (total = sum {e.salary from e in emp
  387.                                 where e.age > 30} )
  388. .ft
  389. .)l
  390. or
  391. .(l
  392. .ft C
  393. retrieve (total = sum {EMP.salary where emp.age > 30})
  394. .ft
  395. .)l
  396. In either case, \*(PP is instructed to find 
  397. the instances in the from_list which
  398. satisfy the qualification and then compute the aggregate of the a_expr
  399. indicated.  
  400. .lp
  401. On the other hand, if there are variables used in the aggregate expression that
  402. are not defined in the from list, e.g:
  403. .(l
  404. .ft C
  405. avg {emp.salary where emp.age = e.age}
  406. .ft
  407. .)l
  408. then this aggregate has a value for each possible value taken on by 
  409. e.age.  For example, the following complete query finds the
  410. average salary of each possible employee age over 18:
  411. .(l
  412. .ft C
  413. retrieve (e.age, avg {emp.salary where emp.age = e.age})
  414.     from e in emp 
  415.     where e.age > 18
  416. .ft
  417. .)l
  418. Such aggregate functions are not supported in Version \*(PV. Furthermore,
  419. in this version, only the a_expr and the where-qualification clause 
  420. are supported.  Therefore, for the above simple sum aggregate, the 
  421. supported query would be the latter.  One other note:  the qualification
  422. will support inheritance, but the expression to be aggregated will not.
  423.  
  424. .uh "Set Expressions"
  425. .lp
  426. .b
  427. Set expressions are not supported in Version \*(PV.
  428. .r
  429. .lp
  430. A
  431. .i set
  432. .i expression
  433. defines a collection of instances from some class
  434. and uses the following syntax:
  435. .(l
  436. .ft C
  437.  {target_list from from_list where qualification}
  438. .ft
  439. .)l
  440. For example, the set of all employee names over 40 is:
  441. .(l
  442. .ft C
  443. {emp.name where emp.age > 40}
  444. .ft
  445. .)l
  446. .fi
  447. In addition, it is legal to construct set expressions which
  448. have an instance variable which is defined outside the scope of
  449. the expression.  For example, the following expression is the
  450. set of employees in each department:
  451. .(l
  452. .ft C
  453. {emp.name where emp.dept = dept.dname}
  454. .ft
  455. .)l
  456. .in .5i
  457. Set expressions can be used in class expressions which
  458. are defined below.
  459. .uh "Class Expression"
  460. .lp
  461. .b
  462. Class expressions are not supported in Version \*(PV.
  463. .r
  464. .lp
  465. .i class
  466. .i expression 
  467. is an expression of the form:
  468. .(l
  469. class_constructor binary_class_operator class_constructor
  470. unary_class_operator class_constructor
  471. .)l
  472. where binary_class_operator is one of the following:
  473. .(l
  474. union        union of two classes
  475. intersect    intersection of two classes
  476. \-        difference of two classes
  477. >>        left class contains right class
  478. <<        right class contains left class
  479. ==        right class equals left class 
  480. .)l
  481. and unary_class_operator can be:
  482. .in .5i
  483. .(l
  484. empty        right class is empty
  485. .)l
  486. .fi
  487. .i class_constructor 
  488. is either an instance variable, 
  489. a class name, the value of a composite field or a set expression.
  490. .lp
  491. An example of a query with a class expression is
  492. one to find all the departments with no employees:
  493. .in .5i
  494. .(l
  495. .ft C
  496. retrieve (dept.dname)
  497.     where empty {emp.name where emp.dept = dept.dname}
  498. .ft
  499. .)l  
  500. .uh "Target_list"
  501. .lp
  502. A
  503. .i "target list"
  504. is a parenthesized, comma-separated list of one
  505. or more elements, each of which must be of the form:
  506. .(l
  507. .ft C
  508. [result_attname  =] a_expr
  509. .ft
  510. .)l
  511. Here, result_attname 
  512. is the name of the attribute to be created (or an
  513. already existing attribute name in the case of update statements.)
  514. If result_attname is not present, then a_expr must 
  515. contain only one attribute name
  516. which is assumed to be the name of the result field.
  517. In Version \*(PV default naming is only used if the a_expr is an attribute.
  518. .uh "Qualification"
  519. .lp
  520. .i qualification 
  521. consists of any number of clauses connected
  522. by the logical operators:
  523. .(l
  524. .ft C
  525. not
  526. and
  527. or
  528. .ft
  529. .)l
  530. A clause is an a_expr that evaluates to a Boolean over a set of instances.
  531. .uh "From List"
  532. .lp
  533. The 
  534. .i from
  535. .i list
  536. is a comma-separated list of 
  537. .i from
  538. .i expressions.
  539. .lp
  540. Each 
  541. .i from
  542. .i expression
  543. is of the form:
  544. .(l
  545. .ft C
  546. instance_variable-1 {, instance_variable-2}
  547.     in class_reference
  548. .ft
  549. .)l
  550. where 
  551. .i class_reference
  552. is of the form
  553. .(l
  554. .ft C
  555. class_name [time_expression] [*]
  556. .ft
  557. .)l
  558. The 
  559. .i from
  560. .i expression
  561. defines one or more instance variables to range over the class indicated
  562. in \fIclass_reference\fR.  
  563. Adding a \fItime_expression\fR will indicate that a historical class
  564. is desired.
  565. One can also request the instance variable to range over all
  566. classes that are beneath the indicated class in the inheritance
  567. hierarchy by postpending the designator `*'.
  568. .uh "Time Expressions"
  569. .lp
  570. A
  571. .i time
  572. .i expression
  573. is in one of two forms:
  574. .(l
  575. .ft C
  576.  [date]
  577.  [date-1, date-2]
  578. .ft
  579. .)l
  580. The first case requires instances that are valid
  581. at the indicated time.
  582. The second case requires instances that are valid at some time within
  583. the date range specified.
  584. If no time expression is indicated, the
  585. default is \*(lqnow\*(rq.  
  586. .lp
  587. In each case, the date is a character string of the form
  588. .(b
  589. .ft C
  590. [MON-FRI] "MMM DD [HH:MM:SS] YYYY" [Timezone]
  591. .fn
  592. .)b
  593. where MMM is the month (Jan \- Dec),
  594. DD is a legal day number in the specified month,
  595. HH:MM:SS is an optional time in that day (24-hour clock),
  596. and YYYY is the year.
  597. If the time of day HH:MM:SS is not specified,
  598. it defaults to midnight at the start of the specified day.
  599. In addition,
  600. all times are interpreted as GMT.
  601. .lp
  602. For example,
  603. .(b
  604. .ft C
  605. ["Jan 1 1990"]
  606. ["Mar 3 00:00:00 1980", "Mar 3 23:59:59 1981"]
  607. .fn
  608. .)b
  609. are valid time specifications.
  610. .uh "SEE ALSO"
  611. .lp
  612. append(commands),
  613. delete(commands),
  614. execute(commands),
  615. replace(commands),
  616. retrieve(commands),
  617. monitor(unix).
  618. .uh BUGS
  619. .lp
  620. The following constructs are not available in Version \*(PV:
  621. .(l
  622. .ft C
  623. class expressions
  624. set expressions
  625. .ft
  626. .)l
  627.